Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
Combining two regex "^[\x20-\x7E]*$" and "\S(.*\S" into one

I have two regex that work separately: ^[\x20-\x7E]*$ and \S(.*\S

But I don't get how to combine the two so it will match them both.

I tried (^[\x20-\x7E]*$)*?(\S(.*\S)?) but it didn't work.

I used this in input tag with pattern="(^[\x20-\x7E]*$)*?(\S(.*\S)?)"

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Combine the two regexes with the pipe symbol. It is the same as the logical OR. Here's a code snippet demonstrating how to use this.

import re

regex_list = ["^[\x20-\x7E]$", "\S(.*\S)"]
regex = '|'.join(regex_list)

print(regex)                       # ^[ -~]$|\S(.*\S)
print(re.search(regex, "C"))       #matches first pattern
print(re.search(regex, "CAT CAT")) #matches second pattern
print(re.search(regex, " 3 "))     #matches neither pattern
about 4 years ago · Santiago Trujillo Denunciar

0

One way to do this is to use word boundaries (\b) instead of the \S anchor:

^\b[\x20-\x7E]*\b$

This would match your given test case Priya@ #432, but would not match priya##23á or Priya@ #432 . You can see an example of this regex in action on Regex101 here.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda